<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="java.net.URLEncoder"%>
<%@page import="com.dreamstall.xiaome.Word"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<%
	Map<String, Word> ready_map = (Map<String, Word>) application
			.getAttribute("ready");

	String result = request.getParameter("result");
	String color = "";
	if (result != null && result.equals("false")) {
		color = "#CF006C";
	}
	if (result != null && result.equals("true")) {
		color = "#6CBC43";
	}
	String last_key = request.getParameter("key");
	Word last_word = null;
	if (last_key != null && !last_key.equals("")) {
		last_word = ready_map.get(last_key);
	}
	if(last_word==null){
		last_word=new Word();
	}

	Object[] keys = ready_map.keySet().toArray();
	String[] s = new String[4];
	s[1] = (String) keys[(new Random().nextInt(keys.length))];
	s[2] = (String) keys[(new Random().nextInt(keys.length))];
	s[3] = (String) keys[(new Random().nextInt(keys.length))];
	s[0] = (String) keys[(new Random().nextInt(keys.length))];

	String key = s[new Random().nextInt(4)];
	Word word = ready_map.get(key);

	Word[] words = new Word[4];
	int i = 0;
	for (String t : s) {
		words[i++] = ready_map.get(t);
	}
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>test.html</title>

		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="this is my page">
		<meta http-equiv="content-type" content="text/html; charset=UTF-8">

		<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
		<style type="text/css">
a {
	display: inline-block;
	width: 100%;
	height: 100%;
}

a:active {
	background: #229DD9;
}

a:link {
	text-decoration: none;
}

a:hover {
	background: #229DD9;
}
</style>
	</head>
	<body bgcolor="black">
		<table border="0" width="100%" height="110%">
			<tr height="2%">
				<th></th>
			</tr>
			<tr height="16%">
				<th width="5.3%"></th>
				<td width="86.4%" colspan=3 bgcolor="<%=color%>">
					<font size="3" color="white"><%=last_word.getWord() + " "
					+ last_word.getPronunciation()%><br /> </font><font size="2"
						color="white"><%=last_word.getMeansHtml()%></font>
				</td>
				<th width="7.3%"></th>
			</tr>
			<tr height="2%">
				<th></th>
			</tr>
			<tr height="16%">
				<th width="5.3%"></th>
				<td width="86.4%" colspan=3>
					<font size="7" color="white"><%=word.getWord() %></font> <font size="4" color="white"><%=word.getPronunciation() %></font>
				</td>
				<th width="7.3%"></th>
			</tr>
			<tr height="2%">
				<th></th>
			</tr>
			<tr height="29%">
				<th width="5.3%"></th>
				<td width="41.1%" bgcolor="#006AB8">
					<a
						href="test.jsp?abc=alkdfjakkcmnasdfadskj<%=new Random().nextDouble()%>asdkfjadsfjas<%=new Random().nextLong()%>asdfa&result=<%=(key.equals(words[0].getWord()))%>&key=<%=key%>"><font
						size="7" color="white">A:<br /> </font><font size="6"
						color="white"><%=words[0].getMeansHtml()%></font> </a>
				</td>
				<th width="4.2%"></th>
				<td width="41.1%" bgcolor="#006AB8">
					<a
						href="test.jsp?abc=alkdfjakkcmnasdfadskj<%=new Random().nextDouble()%>asdkfjadsfjas<%=new Random().nextLong()%>asdfa&result=<%=(key.equals(words[1].getWord()))%>&key=<%=key%>"><font
						size="7" color="white">B:<br /> </font><font size="6"
						color="white"><%=words[1].getMeansHtml()%></font> </a>
				</td>
				<th width="7.3%"></th>
			</tr>
			<tr height="2%">
				<th></th>
			</tr>
			<tr height="29%">
				<th width="5.3%" bgcolor=""></th>
				<td width="41.1%" bgcolor="#006AB8">
					<a
						href="test.jsp?abc=alkdfjakkcmnasdfadskj<%=new Random().nextDouble()%>asdkfjadsfjas<%=new Random().nextLong()%>asdfa&result=<%=(key.equals(words[2].getWord()))%>&key=<%=key%>"><font
						size="7" color="white">C:<br /> </font><font size="6"
						color="white"><%=words[2].getMeansHtml()%></font> </a>
				</td>
				<th width="4.2%"></th>
				<td width="41.1%" bgcolor="#006AB8">
					<a
						href="test.jsp?abc=alkdfjakkcmnasdfadskj<%=new Random().nextDouble()%>asdkfjadsfjas<%=new Random().nextLong()%>asdfa&result=<%=(key.equals(words[3].getWord()))%>&key=<%=key%>"><font
						size="7" color="white">D:<br /> </font><font size="6"
						color="white"><%=words[3].getMeansHtml()%></font> </a>
				</td>
				<th width="7.3%"></th>
			</tr>
			<tr height="2%">
				<th></th>
			</tr>


		</table>
	</body>
</html>
